
#include <iostream>

using namespace std;

class Widget
{
public:
    Widget()
    {
        fptr[0] = &f;
        //fptr[1] = &g;
        //fptr[2] = &h;
        //fptr[3] = &i;
    }

    void select(int idex, int val)
    {
        if(idex<0 || idex>cnt)
            return ;
        (this->*fptr[idex])(val);
    }

    int count()
    {
        return cnt;
    }

private:
    void f(int val){ cout<<"f() = "<<val<<endl; }
    void g(int val){ cout<<"g() = "<<val<<endl; }
    void h(int val){ cout<<"h() = "<<val<<endl; }
    void i(int val){ cout<<"i() = "<<val<<endl; }

    enum{cnt = 4};
    void (Widget::*fptr[cnt])(int); //指向Widget类函数的指针
};

int main(void)
{
    Widget w;
#if 0
    for(int i=0; i<w.mcnt; ++i)
    {
        w.select(i, 1);
    }
    #endif
    return 0;
}

